home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / slide.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  9.3 KB  |  256 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software: you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 3 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ;
  17. ;
  18. ; slide.scm   version 0.41   2004/03/28
  19. ;
  20. ; CHANGE-LOG:
  21. ; 0.20 - first public release
  22. ; 0.30 - some code cleanup
  23. ;        now uses the rotate plug-in to improve speed
  24. ; 0.40 - changes to work with gimp-1.1
  25. ;        if the image was rotated, rotate the whole thing back when finished
  26. ; 0.41 - changes to work with gimp-2.0, slightly correct text offsets,
  27. ;        Nils Philippsen <nphilipp@redhat.com> 2004/03/28
  28. ;
  29. ; !still in development!
  30. ; TODO: - change the script so that the film is rotated, not the image
  31. ;       - antialiasing
  32. ;       - make 'add background' an option
  33. ;       - ?
  34. ;
  35. ; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
  36. ;
  37. ; makes your picture look like a slide
  38. ;
  39. ; The script works on RGB and grayscale images that contain only
  40. ; one layer. The image is cropped to fit into an aspect ratio of 1:1,5.
  41. ; It creates a copy of the image or can optionally work on the original.
  42. ; The script uses the current background color to create a background
  43. ; layer.
  44.  
  45.  
  46. (define (script-fu-slide img
  47.                          drawable
  48.                          text
  49.                          number
  50.                          fontname
  51.                          font-color
  52.                          work-on-copy)
  53.  
  54.   (define (crop width height ratio)
  55.     (if (>= width (* ratio height))
  56.         (* ratio height)
  57.         width
  58.     )
  59.   )
  60.  
  61.   (let* (
  62.         (type (car (gimp-drawable-type-with-alpha drawable)))
  63.         (image (cond ((= work-on-copy TRUE)
  64.                       (car (gimp-image-duplicate img)))
  65.                      ((= work-on-copy FALSE)
  66.                       img)))
  67.         (owidth (car (gimp-image-width image)))
  68.         (oheight (car (gimp-image-height image)))
  69.         (ratio (if (>= owidth oheight) (/ 3 2)
  70.                                        (/ 2 3)))
  71.         (crop-width (crop owidth oheight ratio))
  72.         (crop-height (/ crop-width ratio))
  73.         (width (* (max crop-width crop-height) 1.05))
  74.         (height (* (min crop-width crop-height) 1.5))
  75.         (hole-width (/ width 20))
  76.         (hole-space (/ width 8))
  77.         (hole-height (/ width 12))
  78.         (hole-radius (/ hole-width 4))
  79.         (hole-start (- (/ (rand 1000) 1000) 0.5))
  80.         (film-layer (car (gimp-layer-new image
  81.                                          width
  82.                                          height
  83.                                          type
  84.                                          "Film"
  85.                                          100
  86.                                          NORMAL-MODE)))
  87.         (bg-layer (car (gimp-layer-new image
  88.                                        width
  89.                                        height
  90.                                        type
  91.                                        "Background"
  92.                                        100
  93.                                        NORMAL-MODE)))
  94.         (pic-layer (car (gimp-image-get-active-drawable image)))
  95.         (numbera (string-append number "A"))
  96.         )
  97.  
  98.   (gimp-context-push)
  99.  
  100.   (gimp-image-undo-disable image)
  101.  
  102. ; add an alpha channel to the image
  103.   (gimp-layer-add-alpha pic-layer)
  104.  
  105. ; crop, resize and eventually rotate the image
  106.   (gimp-image-crop image
  107.                    crop-width
  108.                    crop-height
  109.                    (/ (- owidth crop-width) 2)
  110.                    (/ (- oheight crop-height) 2))
  111.   (gimp-image-resize image
  112.                      width
  113.                      height
  114.                      (/ (- width crop-width) 2)
  115.                      (/ (- height crop-height) 2))
  116.   (if (< ratio 1)
  117.       (plug-in-rotate RUN-NONINTERACTIVE image pic-layer 1 FALSE)
  118.   )
  119.  
  120. ; add the background layer
  121.   (gimp-drawable-fill bg-layer BACKGROUND-FILL)
  122.   (gimp-image-add-layer image bg-layer -1)
  123.  
  124. ; add the film layer
  125.   (gimp-context-set-background '(0 0 0))
  126.   (gimp-drawable-fill film-layer BACKGROUND-FILL)
  127.   (gimp-image-add-layer image film-layer -1)
  128.  
  129. ; add the text
  130.   (gimp-context-set-foreground font-color)
  131.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  132.                                             film-layer
  133.                                             (+ hole-start (* -0.25 width))
  134.                                             (* 0.01 height)
  135.                                             text
  136.                                             0
  137.                                             TRUE
  138.                                             (* 0.040 height) PIXELS fontname)))
  139.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  140.                                             film-layer
  141.                                             (+ hole-start (* 0.75 width))
  142.                                             (* 0.01 height)
  143.                                             text
  144.                                             0
  145.                                             TRUE
  146.                                             (* 0.040 height) PIXELS
  147.                                             fontname )))
  148.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  149.                                             film-layer
  150.                                             (+ hole-start (* 0.35 width))
  151.                                             0.0
  152.                                             number
  153.                                             0
  154.                                             TRUE
  155.                                             (* 0.050 height) PIXELS
  156.                                             fontname )))
  157.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  158.                                             film-layer
  159.                                             (+ hole-start (* 0.35 width))
  160.                                             (* 0.94 height)
  161.                                             number
  162.                                             0
  163.                                             TRUE
  164.                                             (* 0.050 height) PIXELS
  165.                                             fontname )))
  166.   (gimp-floating-sel-anchor (car (gimp-text-fontname image
  167.                                             film-layer
  168.                                             (+ hole-start (* 0.85 width))
  169.                                             (* 0.945 height)
  170.                                             numbera
  171.                                             0
  172.                                             TRUE
  173.                                             (* 0.045 height) PIXELS
  174.                                             fontname )))
  175.  
  176. ; create a mask for the holes and cut them out
  177.   (let* (
  178.         (film-mask (car (gimp-layer-create-mask film-layer ADD-WHITE-MASK)))
  179.         (hole hole-start)
  180.         (top-y (* height 0.06))
  181.         (bottom-y (* height 0.855))
  182.         )
  183.  
  184.     (gimp-layer-add-mask film-layer film-mask)
  185.  
  186.     (gimp-selection-none image)
  187.     (while (< hole 8)
  188.            (gimp-rect-select image
  189.                              (* hole-space hole)
  190.                              top-y
  191.                              hole-width
  192.                              hole-height
  193.                              CHANNEL-OP-ADD
  194.                              FALSE
  195.                              0)
  196.            (gimp-rect-select image
  197.                              (* hole-space hole)
  198.                              bottom-y
  199.                              hole-width
  200.                              hole-height
  201.                              CHANNEL-OP-ADD
  202.                              FALSE
  203.                              0)
  204.            (set! hole (+ hole 1))
  205.     )
  206.  
  207.     (gimp-context-set-foreground '(0 0 0))
  208.     (gimp-edit-fill film-mask BACKGROUND-FILL)
  209.     (gimp-selection-none image)
  210.     (plug-in-gauss-rle RUN-NONINTERACTIVE image film-mask hole-radius TRUE TRUE)
  211.     (gimp-threshold film-mask 127 255)
  212.  
  213.     (gimp-layer-remove-mask film-layer MASK-APPLY)
  214.   )
  215.  
  216. ; reorder the layers
  217.   (gimp-image-raise-layer image pic-layer)
  218.   (gimp-image-raise-layer image pic-layer)
  219.  
  220. ; eventually rotate the whole thing back
  221.   (if (< ratio 1)
  222.       (plug-in-rotate RUN-NONINTERACTIVE image pic-layer 3 TRUE)
  223.   )
  224.  
  225. ; clean up after the script
  226.   (gimp-selection-none image)
  227.   (gimp-image-undo-enable image)
  228.   (if (= work-on-copy TRUE)
  229.       (gimp-display-new image)
  230.   )
  231.  
  232.   (gimp-displays-flush)
  233.  
  234.   (gimp-context-pop)
  235.   )
  236. )
  237.  
  238. (script-fu-register "script-fu-slide"
  239.   _"_Slide..."
  240.   _"Add a slide-film like frame, sprocket holes, and labels to an image"
  241.   "Sven Neumann <sven@gimp.org>"
  242.   "Sven Neumann"
  243.   "2004/03/28"
  244.   "RGB GRAY"
  245.   SF-IMAGE     "Image"         0
  246.   SF-DRAWABLE  "Drawable"      0
  247.   SF-STRING   _"Text"          "GIMP"
  248.   SF-STRING   _"Number"        "32"
  249.   SF-FONT     _"Font"          "Serif"
  250.   SF-COLOR    _"Font color"    '(255 180 0)
  251.   SF-TOGGLE   _"Work on copy"  TRUE
  252. )
  253.  
  254. (script-fu-menu-register "script-fu-slide"
  255.                          "<Image>/Filters/Decor")
  256.